//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef _HASH_H
#define _HASH_H

/*
 * This is the root of the hashed object.  You shouldn't monkey
 * with it directly.
 */
struct hash
{
    IMutex *h_lock;
    int h_hashsize;      /* Width of h_hash array */
    UInt32 h_hashmask;    /* Bit mask to match array size */
    struct hash_node     /* Chains under each hash value */
        *h_hash[1];
};

/*
 * Hash collision chains.  An internal data structure.
 */
struct hash_node
{
    struct hash_node *h_next;    /* Next on hash chain */
    long h_key;                  /* Key for this node */
    void *h_data;                /*  ...corresponding value */
};

/*
 * Smoke and mirrors to avoid name space pollution
 */
#define hash_alloc __hash_alloc
#define hash_insert __hash_insert
#define hash_delete __hash_delete
#define hash_lookup __hash_lookup
#define hash_dealloc __hash_dealloc
#define hash_foreach __hash_foreach
#define hash_size __hash_size

/*
 * Hash routines
 */
EXTERN_C struct hash *hash_alloc(int);
EXTERN_C Boolean hash_insert(struct hash *, long, void *);
EXTERN_C Boolean hash_delete(struct hash *, long);
EXTERN_C PVoid hash_lookup(struct hash *, long);
EXTERN_C Void hash_dealloc(struct hash *);
EXTERN_C Void hash_foreach(struct hash *, intfun, void *);
EXTERN_C UInt32 hash_size(struct hash *);

#endif /* _HASH_H */
